/********************************************************
* "SWITCH.C":                                           *
* Implementation file for the STK500 SWITCH PORT driver.*
* The SWITCHES are connected to the PA pins.            *
* Henning Hargaard, 19/10 2011                          *
*********************************************************/
#include <avr/io.h>

#define MAX_SWITCH_NR 7

// Prepare the switch port
void initSwitchPort()
{
	DDRA = 0;
	PORTA = 0xff;
}

// Reads all switches at a time
unsigned char switchStatus()
{
	unsigned char status;
	status = ~PINA;
	return status;
}

// Returns TRUE, if the switch having the number
// "switch_nr" is activated - otherwise return FALSE
unsigned char switchOn(unsigned char switch_nr)
{
	unsigned char status = 0;
	unsigned char mask;
	if (switch_nr <= MAX_SWITCH_NR)
	{
		mask = (1 << switch_nr);
		status = (mask & ~PINA);	
	}		
	return status;
} 
